#
# ParseOpt.rb - Uses the optparse library to parse command line options.
#

require 'optparse'

class ParseOpt
  
  # Initializes the instance with the array containing the command line
  # specified for this execution and version number to report.
  def initialize(array, version)
    @argum = array
    @ver = version
    @verbose = false
    @debug = false
    @pretend = false
    @nooptimize = false
  end

  attr_reader :verbose, :debug, :pretend, :nooptimize
  
  # Does the actual parsing of the command line options.
  #
  # The parsing is done in-place on the ARGV array, so that recognized options
  # are 'stripped' from the array.
  def parsing()
    opts = OptionParser.new do |opts|
      opts.on("-v", "--verbose", "Enables the verbose mode" ) do |v|
        @verbose = true
      end
      opts.on("-d", "--debug", "Enables the debug prints (very verbose)") do |d|
        @debug = true
      end
      opts.on("-n", "--nooptimize", "Disables optimizer") do |noopt|
        @nooptimize = true
      end
      opts.on("-p", "--pretend", "Just parses the expression, does no matching (useful with -v to see how the automaton got built)") do |p|
        @pretend = true
      end
      opts.on("--version", "Shows the software version") do |ver|
        print @ver + "\n\n"
        return
      end
      #opts.on("-q", "--quiet", "Disables all output, except for number of matches") do |q|
       # quiet = true
      #end
      opts.on_tail("-h", "--help", "Shows this usage statement") do |h|
        puts opts
        return
      end
    end

    begin
      opts.parse!(ARGV)

    rescue Exception => e
      puts e, "", opts
      exit(1)
    end
  end
end